package cn.cvs.dao;

import cn.cvs.pojo.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
public interface SysUserMapper {
    //查询所有用户
    List<SysUser> queryAll();

    //根据用户账号和密码查询
    @Select("select * from t_sys_user where account=#{account} and password=#{password}")
    SysUser queryByAccountAndpwd(@Param("account") String account, @Param("password") String password);

    //查询所有用户
    @Select(" select * from t_sys_user")
    List<SysUser> findAll();

    //依据编号查询用户
     SysUser queryById(@Param("id") int id);

    //依据编号查询用户
    SysUser findById(Integer id);

    //多条件查询  真实姓名realName (模糊查询)  角色编号(roleId)
    List<SysUser> queryList(SysUser sysUser);

    //多条件 Map传参
    List<SysUser> queryListWithMap(Map map);

    //多条件 使用注解@Param
    List<SysUser> queryListWithParam(@Param("realName") String realName, @Param("roleId") Integer roleId);

    //查询所有用户(带有角色名称 userRoleName)****
    List<SysUser> queryListWithRoleName();

    //查询所有用户（带有关联属性，角色对象）****
    List<SysUser> queryListWithRole();

    //添加一个用户
    int insertSysUser(SysUser sysUser);

    //修改
    int modify(SysUser sysUser);

    //删除
    int deleteById(@Param("id") Integer id);

    //查找用户的所有地址
    List<SysUser> queryAllSysUserandAddress();

    //动态查询
    //if
    List<SysUser> queryDList(@Param("realName") String realName, @Param("realId") Integer roleId);

    //where - if
    List<SysUser> queryDList2(@Param("realName") String realName, @Param("realId") Integer roleId);

    //多条件寻找  choose    只要有一个条件满足了就执行
    List<SysUser> queryDList3(@Param("account") String account, @Param("realName") String realName, @Param("roleId") Integer roleId);

    //foreach  集合遍历   list
    List<SysUser> queryForEach(@Param("ids") List<Integer> ids);

    //foreach  集合遍历   set
    List<SysUser> queryForEachSet(@Param("ids") Set<Integer> ids);

    //foreach  集合遍历   set
    List<SysUser> queryForEachInteger(@Param("ids") Integer[] ids);

    //foreach  集合遍历   set
    List<SysUser> queryForEachMap(@Param("ids") Map<String, Integer> ids);

    //修改if - else
    int updateSysUSer(SysUser sysUser);

    //  查询Trim
    List<SysUser> queryTrimList(@Param("realName") String realName, @Param("roleId") Integer roleId);

    //   修改Trim
    int updateTrim(SysUser sysUser);

    //分页
    List<SysUser> queryPage(@Param("pageBean") Integer pageBean, @Param("pageSize") Integer pageSize);

    //依据realName和realId查询加分页
    //使用动态sql
    List<SysUser> queryByPage(@Param("realName") String realName, @Param("roleId") Integer roleId, @Param("pageBean") Integer pageBean, @Param("pageSize") Integer pageSize);

    //分页记录数
    int queryByPageCount(@Param("realName") String realName, @Param("roleId") Integer roleId);

    //依据account查询用户是否存在
    @Select("select COUNT(0) from t_sys_user where account=#{account}")
    int queryUserExist(String account);

}
